package com.ruoyi.livedemo.mapper;

import com.ruoyi.livedemo.entity.DiaryMedia;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DiaryMediaMapper {

    @Select("SELECT * FROM diary_media WHERE diary_id=#{diaryId} ORDER BY sort_order ASC, id ASC")
    List<DiaryMedia> findByDiary(Long diaryId);

    @Insert("INSERT INTO diary_media (diary_id, file_path, media_type, caption, sort_order) VALUES (#{diaryId}, #{filePath}, #{mediaType}, #{caption}, #{sortOrder})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(DiaryMedia media);

    @Delete("DELETE FROM diary_media WHERE diary_id=#{diaryId}")
    int deleteByDiary(Long diaryId);

    @Delete("DELETE FROM diary_media WHERE id=#{id}")
    int deleteById(Long id);
}


